﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Data;

namespace nGSO.Performance
{
    public class AnalyticsManager : IDisposable
    {
        #region get multimodal optimization cases
        private static string casesQuery = @"SELECT FunctionKey, Population, MaxIterations, RadialSensorRange, DesiredNoOfNeighbors, 
                                            avg(OverallEfficiency) AvgEfficiency,
                                            avg(cast( DetectedPeaks as real)) AvgDetectedPeaks
                                            FROM PerfTests
                                            WHERE PerfKpResultId is null AND FunctionKey like 'AgentFunction%' AND EndDate is not null
                                            GROUP BY FunctionKey, Population, MaxIterations, RadialSensorRange, DesiredNoOfNeighbors";
        #endregion

        public Model.DataModelEntities Context {get; private set;} 

        public AnalyticsManager()
        {
            Context = PerfDatabase.GetContext();
        }

        public IList<AnalyticsOptions> GetAnalyticsParameterModel()
        {
            var listOptions = Context.ExecuteStoreQuery<AnalyticsOptions>(casesQuery, null).ToList();

            return listOptions;
        }

        public void Dispose()
        {
            Context.Dispose();
        }

    }

    public class AnalyticsOptions
    {
        public string FunctionKey { get;set; }
        public int Population {get;set;}
        public int MaxIterations {get;set;}
        public float RadialSensorRange {get;set;}
        public int DesiredNoOfNeighbors {get;set;}
        public double AvgEfficiency { get; set; }
        public double AvgDetectedPeaks { get; set; }
    }
}

